package cc.catface.common.output;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;

@Data
@ToString
@NoArgsConstructor
@AllArgsConstructor
public class Result<T> {

    private String code;
    private String message;
    private T data;

    public static <T> Result<T> success(T data) {//成功
        return new Result<>(ErrorCode.SUCCESS.getCode(), ErrorCode.SUCCESS.getMessage(), data);
    }

    public static <T> Result<T> success() {
        return success(null);
    }


    public static Result error(String code, String message) {//失败
        return new Result<>(code, message, null);
    }

    public static Result error(IBaseCode baseCode) {
        return new Result<>(baseCode.getCode(), baseCode.getMessage(), null);
    }

    public static Result error(String message) {
        return new Result<>(ErrorCode.FAILURE.getCode(), message, null);
    }
}
